--dao

package csc.daonjpa.java.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;

import csc.daonjpa.java.controller.EntityManagerFactoryUtil;
import csc.daonjpa.java.domain.Customer;
import csc.daonjpa.java.domain.Transaction;

@Component
public class TransactionDAO {

	//return transaction history of customer -- customer action
	public List<Transaction> customerTransferList(Long loginId){
		EntityManager em = EntityManagerFactoryUtil.createEntityManager();
		TypedQuery<Transaction> query = em.createQuery("SELECT t FROM Transaction t" + Transaction.class.getName()
										+ "JOIN t.customer c" + Transaction.class.getName() + 
										"WHERE t.sendCustomer= :(SELECT c.id FROM Customer c WHERE c.loginId= :loginId)"
										, Transaction.class);
		query.setParameter("loginId", loginId);
		List<Transaction> transactions = query.getResultList();
		return transactions;
	}
	
	/*public List<Transaction> customerReceiveTransfer(){
		EntityManager em = EntityManagerFactoryUtil.createEntityManager();
		TypedQuery<Transaction> query = em.createQuery("SELECT t FROM Transaction t WHERE t.receiveCustomer= :receiveCustomer"
										+ Transaction.class.getName() + "JOIN t.accountNumber c"
										+ Customer.class + "WHERE c.id= :receivedCustomer", 
										Transaction.class);
	}*/
}



--service

package csc.daonjpa.java.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import csc.daonjpa.java.dao.TransactionDAO;
import csc.daonjpa.java.domain.Transaction;


public class TransactionService {
	@Autowired
	private TransactionDAO transactionDAO;

	/**
	 * @return the transactionDAO
	 */
	public TransactionDAO getTransactionDAO() {
		return transactionDAO;
	}

	/**
	 * @param transactionDAO the transactionDAO to set
	 */
	public void setTransactionDAO(TransactionDAO transactionDAO) {
		this.transactionDAO = transactionDAO;
	}
	
	public List<Transaction> getTransaction(Long customerLoginId){
		return transactionDAO.customerTransferList(customerLoginId);
	}
	
}
